﻿using CommunityToolkit.Mvvm.ComponentModel;
using Koala.Pro.Common;
using Koala.Pro.Core;
using Koala.Pro.Core.Models;
using Koala.Pro.Models;
using Koala.Pro.Services;

namespace Koala.Pro.Helpers
{
    public partial class DictItemsModel : ObservableObject
    {
        [ObservableProperty]
        private List<CListItem> genderItems = new List<CListItem>();

        [ObservableProperty]
        private List<CListItem> isExpandToYesNoItems = new List<CListItem>();

        [ObservableProperty]
        private List<CListItem> isVisibleToYesNoItems = new List<CListItem>();

        [ObservableProperty]
        private List<CListItem> isForbidToStrItems = new List<CListItem>();

        [ObservableProperty]
        private List<CListItem> ouCategoryItems = new List<CListItem>();

        [ObservableProperty]
        private List<CListItem> roleTypeItems = new List<CListItem>();

        [ObservableProperty]
        private List<CListItem> authorizedItems = new List<CListItem>();

        [ObservableProperty]
        private List<CListItem> operationLogTypeItems = new List<CListItem>();

        [ObservableProperty]
        private List<CListItem> provinceItems = new List<CListItem>();

        [ObservableProperty]
        private List<CListItem> markColorItems = new List<CListItem>();


        public DictItemsModel()
        {
            InitDictItem();
        }

        public async Task InitDictItem()
        {
            GenderItems = new List<CListItem>
        {
            new CListItem(""),
            new CListItem("男"),
            new CListItem("女")
        };
            IsExpandToYesNoItems = new List<CListItem>
        {
            new CListItem(""),
            new CListItem
            {
                Text = "是",
                Value = "1"
            },
            new CListItem
            {
                Text = "否",
                Value = "0"
            }
        };
            IsVisibleToYesNoItems = new List<CListItem>
        {
            new CListItem(""),
            new CListItem
            {
                Text = "是",
                Value = "1"
            },
            new CListItem
            {
                Text = "否",
                Value = "0"
            }
        };
            IsForbidToStrItems = new List<CListItem>
        {
            new CListItem(""),
            new CListItem
            {
                Text = "禁用",
                Value = "1"
            },
            new CListItem
            {
                Text = "不禁用",
                Value = "0"
            }
        };
            OuCategoryItems = (from s in EnumHelper.GetMemberNames<OUCategoryEnum>()
                               select new CListItem(s)).ToList();
            OuCategoryItems.Insert(0, new CListItem(""));

            RoleTypeItems = (from s in EnumHelper.GetMemberNames<RoleCategoryEnum>()
                             select new CListItem(s)).ToList();
            RoleTypeItems.Insert(0, new CListItem(""));


            AuthorizedItems = (from s in EnumHelper.GetMemberKeyValue<AuthorizeType>()
                               select new CListItem(s.Key, s.Value)).ToList();
            AuthorizedItems.Insert(0, new CListItem(""));


            List<string> list = await BLLFactory<IOperationLogService>.Instance.GetFieldList((OperationLogInfo s) => s.OperationType);
            if (list != null && list.Count > 0)
            {
                OperationLogTypeItems = list.Select((string s) => new CListItem(s)).ToList();
                OperationLogTypeItems.Insert(0, new CListItem(""));
            }


            //ListResultDto<ProvinceInfo> listResultDto = await BLLFactory<IProvinceService>.Instance.GetAllAsync();
            //if (listResultDto != null && listResultDto.Items.Count > 0)
            //{
            //    ProvinceItems = listResultDto.Items.Select((ProvinceInfo s) => new CListItem(s.ProvinceName, s.Id)).ToList();
            //    ProvinceItems.Insert(0, new CListItem(""));
            //}

            MarkColorItems = new List<CListItem>
            {
                new CListItem("红色", "Red"),
                new CListItem("橙色", "Orange"),
                new CListItem("绿色", "Green"),
                new CListItem("蓝色", "Blue"),
                new CListItem("紫色", "Purple"),
                new CListItem("黑色", "Black"),
                new CListItem("无", "Empty")
            };
        }

        public void NotifyChanged(string propertyName)
        {
            OnPropertyChanged(propertyName);
        }
    }
}